package com.ews.onlineexchange.controller.assess;

import java.util.List;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.model.assess.AssessRecord;
import com.ews.onlineexchange.model.assess.Dict;
import com.ews.onlineexchange.service.EntityHome;

@Named
@ConversationScoped
public class ExistAssessRecordHome extends EntityHome<AssessRecord, String> {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	
	@Inject
	AssessReocrdLocator 		assessReocrdLocator;

	private ServiceSupplier		supplier;
	private Dict				dict;

	@Override
	public AssessRecord loadInstance() {
		
		/*
		 * 根据ID检索到相关记录，直接返回
		 */
		AssessRecord instance = super.loadInstance();		
		if ( instance != null ) {
			return instance;
		}
		
		/*
		 * 如果没有根据ID搜索到，则根据中介、和字典搜索
		 */
		else {
			assessReocrdLocator.setSupplier( getSupplier() );
			assessReocrdLocator.setDict( getDict() );
			List<AssessRecord> resultList = assessReocrdLocator.getResultList();
			if ( resultList.size() > 0 ) {
				instance = resultList.get( 0 );
			}
		}
		
		return instance;
	}

	public ServiceSupplier getSupplier() {
		return supplier;
	}

	public void setSupplier( ServiceSupplier supplier ) {
		this.supplier = supplier;
	}

	public Dict getDict() {
		return dict;
	}

	public void setDict( Dict dict ) {
		this.dict = dict;
	}

}
